package com.gxwy.shenzhou.message;

import com.gxwy.shenzhou.HeaderRequest;
import com.gxwy.shenzhou.SplitString;
import com.gxwy.shenzhou.StringHandler;
import com.gxwy.shenzhou.Supply;


public class HuoQiZhuanZhengCunZhengQuKaiHuRequest implements StringHandler{
 private String zhdh;
 private String pzdh;
 private String mm;
 private String xxh;
 private String jyje;
 private String cq;
 private String llfdfs;
 private String fdll;
 private HeaderRequest header=new HeaderRequest(true);

 
 public HeaderRequest getHeader() {
	return header;
}
public void setHeader(HeaderRequest header) {
	this.header = header;
}
private int reallon=0;

 private static final int ZHDH_LEN=32;
 private static final int PZDH_LEN=9;
 private static final int MM_LEN=6;
 private static final int XXH_LEN=3;
 private static final int JYJE_LEN=15;
 private static final int CQ_LEN=3;
 private static final int LLFDFS_LEN=1;
 private static final int FDLL_LEN=11;
 
 private static final int ZHDH_FLAG=1;
 private static final int PZDH_FLAG=1;
 private static final int MM_FLAG=1;
 private static final int XXH_FLAG=1;
 private static final int JYJE_FLAG=1;
 private static final int CQ_FLAG=1;
 private static final int LLFDFS_FLAG=1;
 private static final int FDLL_FLAG=1;
 private static final int Total_LEN=ZHDH_LEN+PZDH_LEN+MM_LEN+XXH_LEN+
		 JYJE_LEN+CQ_LEN+LLFDFS_LEN+FDLL_LEN;
		 

public String getZhdh() {
	return zhdh;
}
public void setZhdh(String zhdh) throws Exception{
	if(zhdh==null){
		Exception e=new Exception("String is null");
		e.printStackTrace();
	}else if(zhdh.getBytes("gbk").length<ZHDH_LEN){

		this.zhdh=Supply.supply(zhdh,ZHDH_FLAG,ZHDH_LEN);
	}else if(zhdh.getBytes("gbk").length>ZHDH_LEN){
		 Exception e=new Exception("Too Long");
		 e.printStackTrace();
	}else{
		this.zhdh = zhdh;			
	}
}

public String getPzdh() {
	return pzdh;
}
public void setPzdh(String pzdh) throws Exception{
	if(pzdh==null){
		Exception e=new Exception("String is null");
		e.printStackTrace();
	}else if(pzdh.getBytes("gbk").length<PZDH_LEN){
		
		this.pzdh=Supply.supply(pzdh,PZDH_FLAG,PZDH_LEN);;
	}else if(pzdh.getBytes("gbk").length>PZDH_LEN){
		 Exception e=new Exception("Too Long");
		 e.printStackTrace();
	}else{
		this.pzdh = pzdh;			
	}
}
public String getMm() {
	return mm;
}
public void setMm(String mm)  throws Exception{
	if(mm==null){
		Exception e=new Exception("String is null");
		e.printStackTrace();
	}else if(mm.getBytes("gbk").length<MM_LEN){
             
		this.mm=Supply.supply(mm,MM_FLAG,MM_LEN);
	}else if(mm.getBytes("gbk").length>MM_LEN){
		 Exception e=new Exception("Too Long");
		 e.printStackTrace();
	}else{
		this.mm = mm;			
	}
}
public String getXxh() {
	return xxh;
}
public void setXxh(String xxh) throws Exception{
	if(xxh==null){
		Exception e=new Exception("String is null");
		e.printStackTrace();
	}else if(xxh.getBytes("gbk").length<XXH_LEN){
	
		this.xxh=Supply.supply(xxh,XXH_FLAG,XXH_LEN);
	}else if(xxh.getBytes("gbk").length>XXH_LEN){
		 Exception e=new Exception("Too Long");
		 e.printStackTrace();
	}else{
		this.xxh = xxh;			
	}
}
public String getJyje() {
	return jyje;
}
public void setJyje(String jyje) throws Exception{
	if(jyje==null){
		Exception e=new Exception("String is null");
		e.printStackTrace();
	}else if(jyje.getBytes("gbk").length<JYJE_LEN){
//		for(int i=0;i<15-xxh.getBytes("gbk").length;i++){
//			jyje=""+jyje;
//		}
		this.jyje=Supply.supply(jyje,JYJE_FLAG,JYJE_LEN);;
	}else if(jyje.getBytes("gbk").length>JYJE_LEN){
		 Exception e=new Exception("Too Long");
		 e.printStackTrace();
	}else{
		this.jyje = jyje;			
	}
}
public String getCq() {
	return cq;
}
public void setCq(String cq) throws Exception{
	if(cq==null){
		Exception e=new Exception("String is null");
		e.printStackTrace();
	}else if(cq.getBytes("gbk").length<CQ_LEN){

		this.cq=Supply.supply(cq,CQ_FLAG,CQ_LEN);
	}else if(cq.getBytes("gbk").length>CQ_LEN){
		 Exception e=new Exception("Too Long");
		 e.printStackTrace();
	}else{
		this.cq = cq;			
	}
}
public String getLlfdfs() {
	return llfdfs;
}
public void setLlfdfs(String llfdfs)throws Exception {
	if(llfdfs==null){
		Exception e=new Exception("String is null");
		e.printStackTrace();
	}else if(llfdfs.getBytes("gbk").length<LLFDFS_LEN){
	      
		this.llfdfs=Supply.supply(llfdfs,LLFDFS_FLAG,LLFDFS_LEN);;
	}else if(llfdfs.getBytes("gbk").length>LLFDFS_LEN){
		 Exception e=new Exception("Too Long");
		 e.printStackTrace();
	}else{
		this.llfdfs = llfdfs;			
	}
}
public String getFdll() {
	return fdll;
}
public void setFdll(String fdll) throws Exception{
	if(fdll==null){
		Exception e=new Exception("String is null");
		e.printStackTrace();
	}else if(fdll.getBytes("gbk").length<FDLL_LEN){
	     this.fdll=Supply.supply(fdll,FDLL_FLAG,FDLL_LEN);
		
	}else if(fdll.getBytes("gbk").length>FDLL_LEN){
		 Exception e=new Exception("Too Long");
		 e.printStackTrace();
	}else{
		this.fdll = fdll;			
	}
}
public String build () throws Exception{
	if(this.getHeader()==null){
		throw new Exception("Header is null");
	}
	if(this.getZhdh()==null){
		this.setZhdh("");
	}
    if(this.getPzdh()==null){
    	this.setPzdh("");
    }
    if(this.getMm()==null){
    	this.setMm("");
    }
    if(this.getXxh()==null){
    	this.setPzdh("");
    }
    if(this.getJyje()==null){
    	this.setJyje("");
    }
    if(this.getCq()==null){
    	this.setCq("");
    }
    if(this.getLlfdfs()==null){
    	this.setLlfdfs("");
    }
    if(this.getFdll()==null){
    	this.setFdll("");
    	}
    Integer totallen=header.TOTAL_LEN+Total_LEN-header.TOTAL_LEN;
	this.getHeader().setLen(totallen.toString());
	return 
			this.getHeader().build()+
			this.getZhdh()+
 		    this.getPzdh()+
			this.getMm()+
			this.getXxh()+
			this.getJyje()+
			this.getCq()+
			this.getLlfdfs()+
			this.getFdll();
    }
public void parse(String str) throws Exception{
	if(str==null){
		Exception e=new Exception("String is null");
		throw e;
	}else if(str.getBytes("gbk").length<
			header.TOTAL_LEN+
			Total_LEN){
		Exception e=new Exception("Invalid request");
		throw e;
	}else{
		String headerLen=SplitString.splitString(str,reallon, reallon+header.TOTAL_LEN);
		reallon+=header.TOTAL_LEN;
	    
		header.parse(headerLen);		
		 this.setZhdh(SplitString.splitString(str,reallon,reallon+ZHDH_LEN));
		 reallon+=ZHDH_LEN;
		 this.setPzdh(SplitString.splitString(str,reallon,reallon+PZDH_LEN));
		 reallon+=PZDH_LEN;
		 this.setMm(SplitString.splitString(str,reallon,reallon+MM_LEN));
		 reallon+=MM_LEN;
		 this.setXxh(SplitString.splitString(str,reallon,XXH_LEN+reallon));
		 reallon+=XXH_LEN;
		 this.setJyje(SplitString.splitString(str,reallon,reallon+JYJE_LEN));
		 reallon+=JYJE_LEN;
		 this.setCq(SplitString.splitString(str,reallon,reallon+CQ_LEN));
		 reallon+=CQ_LEN;
		 this.setLlfdfs(SplitString.splitString(str,reallon,reallon+LLFDFS_LEN));
		 reallon+=LLFDFS_LEN;
		 this.setFdll(SplitString.splitString(str,reallon,reallon+FDLL_LEN));
	}
  }
public static void main(String args[]) throws Exception{
	HuoQiZhuanZhengCunZhengQuKaiHuRequest a=new HuoQiZhuanZhengCunZhengQuKaiHuRequest();
    a.setCq("1");
    a.setFdll("2");
    a.setJyje("3");
    a.setLlfdfs("4");
    a.setMm("5");
    a.setPzdh("6");
    a.setXxh("7");
    a.setZhdh("8");
   
	a.parse(a.build());
	if(a.getCq().trim().equals("1")){   
		System.out.println("Cqyes");
	}
	if(a.getFdll().trim().equals("2")){
		System.out.print("Fdllyes");
	}
	if(a.getJyje().trim().equals("3")){
		System.out.println("Jyjeyes");
			}
	if(a.getLlfdfs().trim().equals("4")){
		System.out.println("Llfdfsyes");
	}
	if(a.getMm().trim().equals("5")){
		System.out.println("Mmyes");
	}
	if(a.getPzdh().trim().equals("6")){
		System.out.println("Pzdhyes");
	}
	if(a.getXxh().trim().equals("7")){
		System.out.println("Xxhyes");
	}
	if(a.getZhdh().trim().equals("8")){
		System.out.println("Zhdhyes");
	}
	
//	System.out.println(a.getCq());
//	System.out.println(a.getFdll());
//	System.out.println(a.getJyje());
//	System.out.println(a.getLlfdfs());
//	System.out.println(a.getMm());
//	System.out.println(a.getPzdh());
//	System.out.println(a.getXxh());
//	System.out.println(a.getZhdh());
}
 
}
